package com.jianggujin.redis.panel.value;

import java.awt.BorderLayout;
import java.util.Map.Entry;

import javax.swing.JPanel;

import com.jianggujin.redis.component.JEditorTable;
import com.jianggujin.redis.node.RedisKey;
import com.jianggujin.redis.panel.ValuePanel;

public class HashValuePanel extends JPanel implements ValuePanel {
    private JEditorTable valueTable;

    public HashValuePanel() {
        super(new BorderLayout());
        valueTable = new JEditorTable(new String[] { "Key", "Value", "Action" });
        valueTable.setRowSelectionAllowed(false);
        add(valueTable);
    }

    @Override
    public void showValue(RedisKey redisKey) {
        valueTable.removeAllRow();
        for (Entry<String, String> item : redisKey.getClient().hgetAll(redisKey.getKey()).entrySet()) {
            valueTable.addRow(new Object[] { item.getKey(), item.getValue() });
        }
    }

}
